import java.util.Arrays;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}

class Solution {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals, Comparator.comparingInt((v) -> v[1]));
        int prevEnd = Integer.MIN_VALUE;
        int ans = 0;
        for (int[] each : intervals) {
            if (each[0] < prevEnd) {
                ans++;
                continue;
            }
            prevEnd = each[1];
        }
        return ans;
    }
}